package com.guojian.http.handle.route;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.Request;

import com.guojian.http.handle.AbstractJettyHandler;

public class HttpJetty404Handle extends AbstractJettyHandler {

	private static final String URL_NOT_MATCHED = "未匹配到该URL--> %s ,请检查RouteConfig文件";

	@Override
	public void handleJettyRequestResponse(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

		response.setCharacterEncoding("UTF-8");
		response.setStatus(HttpServletResponse.SC_NOT_FOUND);
		response.setContentType(MimeTypes.Type.TEXT_HTML_UTF_8.toString());

		response.getOutputStream().write(String.format(URL_NOT_MATCHED, target).getBytes());
	}

}
